<?php

namespace app\admin\controller;

use think\facade\Request;
use app\common\Common;
use app\admin\service\PartnersServiceNew;

class PartnersNew extends Base
{
    private $service;

    public function __construct(PartnersServiceNew $service)
    {
        parent::__construct();
        $this->service = $service;
    }

    // 渲染列表页
    public function index()
    {
        return view();
    }

    // 渲染详情页
    public function info()
    {
        return view();
    }

    // 下拉列表
    public function select()
    {
        $data = $this->service->getSelectList();
        return Common::success($data);
    }

    // 添加版权方
    public function add()
    {
        $params = Request::param();

        try {
            validate(\app\admin\validate\Partners::class)->scene('add')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $result = $this->service->editPartners($params, $this->getUserInfo());

        if (!$result) {
            return Common::fail();
        }

        return Common::success();
    }

    // 编辑版权方
    public function edit()
    {
        $params = Request::param();

        try {
            validate(\app\admin\validate\Partners::class)->scene('edit')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $result = $this->service->editPartners($params, $this->getUserInfo());

        if (!$result) {
            return Common::fail();
        }

        return Common::success();
    }

    // 版权方列表
    public function list()
    {
        $params = Request::param();

        $data = $this->service->getPartnersList($params);

        return Common::success($data);
    }

    // 版权方详情
    public function detail()
    {
        $params = Request::param();

        try {
            validate(\app\admin\validate\Partners::class)->scene('detail')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $data = $this->service->getPartnersDetail($params['id']);

        return Common::success($data);
    }

    // 删除版权方
    public function delete()
    {
        $params = Request::param();

        try {
            validate(\app\admin\validate\Partners::class)->scene('delete')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $result = $this->service->deletePartners($params['id'], $this->getUserInfo());

        if (!$result) {
            return Common::fail();
        }

        return Common::success();
    }

    // 渲染查看作品页面
    public function see()
    {
        return view();
    }

    // 查看作品
    public function show()
    {
        $params = Request::param();

        try {
            validate(\app\admin\validate\Partners::class)->scene('show')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $data = $this->service->getPartnersWorks($params);

        return Common::success($data);
    }

    // 渲染输入版权结算列表页面
    public function input()
    {
        return view();
    }

    // 输入版权结算
    public function enterSettlement()
    {
        $params = Request::param();

        $data = $this->service->getEnterSettlementPartnersList($params);

        return Common::success($data);
    }

    // 版权方下拉列表
    public function selectList()
    {
        $data = $this->service->getCoOperativeSelectList();

        return Common::success($data);
    }

    // 合作方下拉列表  //202310
    public function selectCooperaterList()
    {
        $params = Request::param();
        $data = $this->service->getCooperaterSelectList($params);

        return Common::success($data);
    }

    // 短剧下拉列表  //202310
    public function selectVideoNameList()
    {
        $params = Request::param();
        $data = $this->service->getVideoNameSelectList($params,$this->getUserInfo());

        return Common::success($data);
    }

    // 添加/编辑合作方
    public function editTheCooperater()
    {
        $params = Request::param();
        try {
            validate(\app\admin\validate\Cooperater::class)->scene('add')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }
        $result = $this->service->editCooperater($params);
        if (!$result) {
            return Common::fail();
        }

        return Common::success();
    }

    // 删除合作方
    public function delTheCooperater()
    {
        $params = Request::param();
        try {
            validate(\app\admin\validate\Cooperater::class)->scene('delete')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }
        $result = $this->service->delCooperater($params);
        if (!$result) {
            return Common::fail();
        }

        return Common::success();
    }
    // 合作方详情
    public function cooperaterDetail()
    {
        $params = Request::param();
        try {
            validate(\app\admin\validate\Partners::class)->scene('detail')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }
        
        $data = $this->service->getCooperateretail($params['id']);

        return Common::success($data);
    }

    //合作方短剧列表展示
    public function cooperaterList()
    {
        $params = Request::param();

        $data = $this->service->getCooperaterList($params);

        return Common::success($data);
    }

    //合作方短剧列表展示
    public function cooperaterCountList()
    {
        $params = Request::param();

        $data = $this->service->getCooperaterCountList($params);

        return Common::success($data);
    }
    
    // 合作方账户管理页面
    public function cooperaterNew()
    {
        return view();
    }

    // 合作方账户管理编辑页面
    public function cooperaterInfoNew()
    {
        return view();
    }

    // 合作方统计页面
    public function cooperaterCountNew()
    {
        return view();
    }
}